﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Tour.Linq.TourDBML;
public partial class AdminManager_Admin_TagManager : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DisplayInfo();
        }
    }

    private void DisplayInfo()
    {
        ListView1.DataSource = TourContext.Tags.OrderByDescending(p => p.Addtime);
        ListView1.DataBind();
    }
    protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    {
        DataPagerUserControl1.SetPage(e.StartRowIndex, e.MaximumRows);
        DisplayInfo();
    }

    protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        Tags tag = TourContext.Tags.First(t => t.ID == e.CommandArgument.ToInt());
        if (tag != null)
        {
            switch (e.CommandName)
            {
                case "TopCommand":
                    tag.IsTop = !tag.IsTop;
                    break;
                case "ReCommand":
                    tag.IsRecommend = !tag.IsRecommend;
                    break;
                case "HotCommand":
                    tag.IsHot = !tag.IsHot;
                    break;
                case "DeleteItem":
                    TourContext.Tags.DeleteOnSubmit(tag);
                    break;
            }
            TourContext.SubmitChanges();
            _Message = "操作成功";
        }
        DisplayInfo();
    }
}
